package com.pjmike.netty.server.handler;

import com.pjmike.netty.protocol.message.packet.request.TrafficDataRequestPacket;
import com.pjmike.netty.protocol.message.packet.response.TrafficDataResponsePacket;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * @Author bj
 * @Description //路口交通参数记录请求处理handler
 * @Date 18:45 2021/1/10
 * @Param
 * @return
 **/
@Slf4j
@ChannelHandler.Sharable
public class TrafficDataHandler extends SimpleChannelInboundHandler<TrafficDataRequestPacket> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, TrafficDataRequestPacket msg) throws Exception {
        log.info("获取到客户端发来的车流参数记录，报文体：{}", msg);
        if (Objects.nonNull(msg)) {
            TrafficDataResponsePacket authResponsePacket = new TrafficDataResponsePacket();
            BeanUtils.copyProperties(msg, authResponsePacket);
            ctx.writeAndFlush(authResponsePacket);
        }
    }
}
